// 多语言配置
const translations = {
    zh: {
        // 页面标题
        pageTitle: "个人作品集 - Python开发者",
        
        // 导航
        navHome: "关于我",
        navTimeline: "专业经历",
        navProjects: "项目作品",
        navContact: "联系方式",
        
        // 头部
        headerTitle: "个人作品集",
        
        // 关于我部分
        aboutTitle: "关于我",
        aboutDescription1: "<strong>Python Developer</strong>，擅长消息中间件、实时数据处理、高可用架构设计。拥有丰富的后端开发经验，专注于构建高性能、可扩展的系统架构。",
        aboutDescription2: "喜欢间谍过家家、幸运星、孤独摇滚、摇曳露营等优秀动漫作品，将二次元文化中的创意与技术创新相结合。",
        aboutDescription3: "通过这个网站，我希望能够展示我的技术能力，同时分享对二次元文化的热爱，与志同道合的朋友交流学习。",
        
        // 技能部分
        skillsTitle: "技能专长",
        
        // 成就部分
        achievementsTitle: "个人成就",
        achievement1Title: "清华大学优秀毕业生",
        achievement1Desc: "2014年本科毕业，获得优秀毕业生荣誉称号",
        achievement2Title: "微软MVP",
        achievement2Desc: "微软最有价值专家，在技术社区贡献突出",
        achievement3Title: "华为开发者认证",
        achievement3Desc: "华为云开发者认证专家",
        
        // 时间线部分
        timelineTitle: "专业经历",
        timeline1Date: "2010-2014",
        timeline1Title: "清华大学",
        timeline1Desc: "本科学习，获得计算机科学与技术学士学位",
        timeline2Date: "2014-2016",
        timeline2Title: "斯坦福大学",
        timeline2Desc: "硕士学习，获得计算机科学硕士学位",
        timeline3Date: "2017-2020",
        timeline3Title: "Google",
        timeline3Desc: "软件工程师，负责分布式系统开发和架构设计",
        timeline4Date: "2021-2023",
        timeline4Title: "OpenAI",
        timeline4Desc: "软件工程师，参与AI系统开发和优化",
        
        // 项目部分
        projectsTitle: "项目作品",
        project1Title: "二次元角色设计集",
        project1Desc: "这是一系列原创的二次元角色设计作品，每个角色都有独特的设定和背景故事。作品融合了传统日式绘画风格与现代数字艺术技术，展现了丰富多样的角色魅力。",
        project2Title: "二次元场景设计",
        project2Desc: "这是一系列精心设计的二次元场景作品，包括幻想城市、神秘森林、未来都市等多种主题。每个场景都注重细节表现和氛围营造，展现了丰富的想象力。",
        project3Title: "二次元主题UI设计",
        project3Desc: "设计了一系列以二次元为主题的UI界面，包括移动应用、网页和游戏界面等。UI风格融合了动漫元素与现代设计理念，既美观又实用。",
        project4Title: "简易计算器开发",
        project4Desc: "这是一个具有基本功能的简易计算器，支持加减乘除四则运算、取余操作、归0功能，以及实时显示计算结果。",
        calculatorTitle: "简易计算器",
        
        // 作品集部分
        galleryTitle: "二次元作品集",
        
        // 联系部分
        contactTitle: "联系方式",
        contactDescription: "如果你也热爱二次元文化，或者对我的作品感兴趣，欢迎随时联系我！无论是交流创作心得，还是洽谈合作事宜，我都很乐意听取你的想法。",
        contactFormName: "姓名：",
        contactFormEmail: "邮箱：",
        contactFormMessage: "留言：",
        contactFormSubmit: "发送消息",
        contactWebsite: "个人网页：",
        contactEmail: "邮箱：",
        
        // 页脚
        footerText: "个人作品集. 保留所有权利。"
    },
    en: {
        // Page Title
        pageTitle: "Personal Portfolio - Python Developer",
        
        // Navigation
        navHome: "About Me",
        navTimeline: "Experience",
        navProjects: "Projects",
        navContact: "Contact",
        
        // Header
        headerTitle: "Personal Portfolio",
        
        // About Section
        aboutTitle: "About Me",
        aboutDescription1: "<strong>Python Developer</strong>, specializing in message middleware, real-time data processing, and high-availability architecture design. With extensive backend development experience, focusing on building high-performance, scalable system architectures.",
        aboutDescription2: "I enjoy excellent anime works such as Spy x Family, Lucky Star, Bocchi the Rock, and Laid-Back Camp, combining creativity from anime culture with technological innovation.",
        aboutDescription3: "Through this website, I hope to showcase my technical skills while sharing my passion for anime culture and learning from like-minded friends.",
        
        // Skills Section
        skillsTitle: "Skills & Expertise",
        
        // Achievements Section
        achievementsTitle: "Personal Achievements",
        achievement1Title: "Tsinghua University Outstanding Graduate",
        achievement1Desc: "Graduated with bachelor's degree in 2014, received outstanding graduate honors",
        achievement2Title: "Microsoft MVP",
        achievement2Desc: "Microsoft Most Valuable Professional, outstanding contributions to technical community",
        achievement3Title: "Huawei Developer Certification",
        achievement3Desc: "Huawei Cloud Developer Certified Expert",
        
        // Timeline Section
        timelineTitle: "Professional Experience",
        timeline1Date: "2010-2014",
        timeline1Title: "Tsinghua University",
        timeline1Desc: "Undergraduate studies, Bachelor's degree in Computer Science and Technology",
        timeline2Date: "2014-2016",
        timeline2Title: "Stanford University",
        timeline2Desc: "Master's studies, Master's degree in Computer Science",
        timeline3Date: "2017-2020",
        timeline3Title: "Google",
        timeline3Desc: "Software Engineer, responsible for distributed system development and architecture design",
        timeline4Date: "2021-2023",
        timeline4Title: "OpenAI",
        timeline4Desc: "Software Engineer, participated in AI system development and optimization",
        
        // Projects Section
        projectsTitle: "Projects",
        project1Title: "Anime Character Design Collection",
        project1Desc: "This is a series of original anime character design works, each character has unique settings and background stories. The works combine traditional Japanese painting style with modern digital art technology, showcasing rich and diverse character charm.",
        project2Title: "Anime Scene Design",
        project2Desc: "This is a series of carefully designed anime scene works, including fantasy cities, mysterious forests, futuristic cities and other themes. Each scene focuses on detail performance and atmosphere creation, showing rich imagination.",
        project3Title: "Anime Theme UI Design",
        project3Desc: "Designed a series of anime-themed UI interfaces, including mobile applications, web pages and game interfaces. The UI style combines anime elements with modern design concepts, both beautiful and practical.",
        project4Title: "Simple Calculator Development",
        project4Desc: "This is a simple calculator with basic functions, supporting four arithmetic operations, modulo operation, reset function, and real-time display of calculation results.",
        calculatorTitle: "Simple Calculator",
        
        // Gallery Section
        galleryTitle: "Anime Art Collection",
        
        // Contact Section
        contactTitle: "Contact",
        contactDescription: "If you also love anime culture or are interested in my works, please feel free to contact me! Whether it's exchanging creative insights or discussing cooperation matters, I'm happy to hear your thoughts.",
        contactFormName: "Name:",
        contactFormEmail: "Email:",
        contactFormMessage: "Message:",
        contactFormSubmit: "Send Message",
        contactWebsite: "Personal Website:",
        contactEmail: "Email:",
        
        // Footer
        footerText: "Personal Portfolio. All rights reserved."
    }
};

// 当前语言
let currentLanguage = 'zh';

// 语言切换函数
function switchLanguage(lang) {
    if (lang === currentLanguage) return;
    
    currentLanguage = lang;
    updatePageLanguage();
    
    // 更新HTML lang属性
    document.documentElement.lang = lang === 'zh' ? 'zh-CN' : 'en';
    
    // 更新语言切换按钮状态
    updateLanguageButtons();
    
    // 保存语言偏好到localStorage
    localStorage.setItem('preferredLanguage', lang);
}

// 更新页面语言
function updatePageLanguage() {
    const t = translations[currentLanguage];
    
    // 更新页面标题
    document.title = t.pageTitle;
    
    // 更新头部
    document.querySelector('header h1').textContent = t.headerTitle;
    
    // 更新导航
    const navLinks = document.querySelectorAll('nav ul li a');
    navLinks[0].textContent = t.navHome;
    navLinks[1].textContent = t.navTimeline;
    navLinks[2].textContent = t.navProjects;
    navLinks[3].textContent = t.navContact;
    
    // 更新关于我部分
    document.querySelector('#about h2').textContent = t.aboutTitle;
    const aboutParagraphs = document.querySelectorAll('#about .about-text p');
    aboutParagraphs[0].innerHTML = t.aboutDescription1;
    aboutParagraphs[1].textContent = t.aboutDescription2;
    aboutParagraphs[2].textContent = t.aboutDescription3;
    
    // 更新技能部分
    document.querySelector('.skills-section h3').textContent = t.skillsTitle;
    
    // 更新成就部分
    document.querySelector('.achievements-section h3').textContent = t.achievementsTitle;
    const achievementItems = document.querySelectorAll('.achievement-item');
    achievementItems[0].querySelector('h4').textContent = t.achievement1Title;
    achievementItems[0].querySelector('p').textContent = t.achievement1Desc;
    achievementItems[1].querySelector('h4').textContent = t.achievement2Title;
    achievementItems[1].querySelector('p').textContent = t.achievement2Desc;
    achievementItems[2].querySelector('h4').textContent = t.achievement3Title;
    achievementItems[2].querySelector('p').textContent = t.achievement3Desc;
    
    // 更新时间线部分
    document.querySelector('#timeline h2').textContent = t.timelineTitle;
    const timelineItems = document.querySelectorAll('.timeline-item');
    timelineItems[0].querySelector('.timeline-date').textContent = t.timeline1Date;
    timelineItems[0].querySelector('h3').textContent = t.timeline1Title;
    timelineItems[0].querySelector('p').textContent = t.timeline1Desc;
    timelineItems[1].querySelector('.timeline-date').textContent = t.timeline2Date;
    timelineItems[1].querySelector('h3').textContent = t.timeline2Title;
    timelineItems[1].querySelector('p').textContent = t.timeline2Desc;
    timelineItems[2].querySelector('.timeline-date').textContent = t.timeline3Date;
    timelineItems[2].querySelector('h3').textContent = t.timeline3Title;
    timelineItems[2].querySelector('p').textContent = t.timeline3Desc;
    timelineItems[3].querySelector('.timeline-date').textContent = t.timeline4Date;
    timelineItems[3].querySelector('h3').textContent = t.timeline4Title;
    timelineItems[3].querySelector('p').textContent = t.timeline4Desc;
    
    // 更新项目部分
    document.querySelector('#projects h2').textContent = t.projectsTitle;
    const projectItems = document.querySelectorAll('.project-item');
    projectItems[0].querySelector('h3').textContent = t.project1Title;
    projectItems[0].querySelector('p').textContent = t.project1Desc;
    projectItems[1].querySelector('h3').textContent = t.project2Title;
    projectItems[1].querySelector('p').textContent = t.project2Desc;
    projectItems[2].querySelector('h3').textContent = t.project3Title;
    projectItems[2].querySelector('p').textContent = t.project3Desc;
    projectItems[3].querySelector('h3').textContent = t.project4Title;
    projectItems[3].querySelector('p').textContent = t.project4Desc;
    
    // 更新计算器标题
    const calculatorHeader = document.querySelector('.calculator-popup-header h4');
    if (calculatorHeader) {
        calculatorHeader.textContent = t.calculatorTitle;
    }
    
    // 更新作品集部分
    document.querySelector('#gallery h2').textContent = t.galleryTitle;
    
    // 更新联系部分
    document.querySelector('#contact h2').textContent = t.contactTitle;
    document.querySelector('#contact .contact-form p').textContent = t.contactDescription;
    
    // 更新表单标签
    const formLabels = document.querySelectorAll('.form-group label');
    formLabels[0].textContent = t.contactFormName;
    formLabels[1].textContent = t.contactFormEmail;
    formLabels[2].textContent = t.contactFormMessage;
    
    // 更新提交按钮
    document.querySelector('.submit-button').textContent = t.contactFormSubmit;
    
    // 更新联系信息
    const contactInfo = document.querySelector('.contact-info');
    contactInfo.innerHTML = `
        <p><strong>${t.contactWebsite}</strong><a href="https://kirineko.github.io" target="_blank">https://kirineko.github.io</a></p>
        <p><strong>${t.contactEmail}</strong><a href="mailto:kirineko@qq.com">kirineko@qq.com</a></p>
    `;
    
    // 更新页脚
    document.querySelector('footer p').innerHTML = `&copy; 2024 ${t.footerText}`;
}

// 更新语言切换按钮状态
function updateLanguageButtons() {
    const zhButton = document.querySelector('.lang-btn[data-lang="zh"]');
    const enButton = document.querySelector('.lang-btn[data-lang="en"]');
    
    if (zhButton && enButton) {
        zhButton.classList.toggle('active', currentLanguage === 'zh');
        enButton.classList.toggle('active', currentLanguage === 'en');
    }
}

// 初始化语言
function initLanguage() {
    console.log('语言初始化开始...');
    
    // 从localStorage获取保存的语言偏好
    const savedLanguage = localStorage.getItem('preferredLanguage') || 'zh';
    console.log('保存的语言:', savedLanguage);
    
    // 绑定语言切换事件
    const langButtons = document.querySelectorAll('.lang-btn');
    console.log('找到语言按钮数量:', langButtons.length);
    
    langButtons.forEach(btn => {
        btn.addEventListener('click', function() {
            console.log('点击语言按钮:', this.dataset.lang);
            switchLanguage(this.dataset.lang);
        });
    });
    
    // 设置初始语言
    setTimeout(() => {
        console.log('设置初始语言:', savedLanguage);
        switchLanguage(savedLanguage);
    }, 100);
}

// 导出函数供其他文件使用
window.switchLanguage = switchLanguage;
window.initLanguage = initLanguage;